using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;

namespace My.IdlConverter.Registration
{
    static class HibernateHelper
    {
        private static readonly object lockObj = new object();
        private static ISessionFactory _factory;

        public static ISession OpenSession()
        {
            if (_factory == null)
            {
                lock (lockObj)
                {
                    if (_factory == null)
                    {
                        NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
                        cfg.Configure();
                        cfg.AddAssembly("My.IdlConverter.Registration");
                        _factory = cfg.BuildSessionFactory();
                        return _factory.OpenSession();
                    }
                }
            }
            return _factory.OpenSession();
        }
    }
}
